def javaBuildDocker(body) {
    node {
        gid = sh (
            script: "stat -c %g /run/containerd/containerd.sock",
            returnStdout: true,
        ).trim()

        docker.withRegistry('https://im30cr.tencentcloudcr.com', 'im30cr') {
            docker.image("im30/java-build-202:v1").pull()
            // 挂载 /ect/hosts 是为了在容器中也能解析公司机房 gitlab 的域名
            docker.image("im30/java-build-202:v1").inside(
                    "-v /data/pkgs/.m2/repository:/home/im30/.m2/repository \
                     -v /home/im30/.ssh:/home/im30/.ssh \
                     -v /etc/hosts:/etc/hosts \
                     -v /usr/bin/docker:/usr/bin/docker \
                     -v /var/run/docker.sock:/var/run/docker.sock \
                     -v /data/jenkins/tools/sec_scan:/data/jenkins/tools/sec_scan \
                     --group-add ${gid}"
                ) {
                withEnv(["MAVEN_OPTS=-Dfile.encoding=UTF-8"]) {
                    body()
                }
            }
        }
    }
}

def nodeBuildDocker(body) {
    node {
        gid = sh (
            script: "stat -c %g /run/containerd/containerd.sock",
            returnStdout: true,
        ).trim()

        docker.withRegistry('https://im30cr.tencentcloudcr.com', 'im30cr') {
            docker.image("im30/nodejs-build:v80").pull()
            docker.image("im30/nodejs-build:v80").inside(
                    "-v /data/pkgs/.npm:/home/im30/.npm \
                     -v /home/im30/.ssh:/home/im30/.ssh \
                     -v /usr/bin/docker:/usr/bin/docker \
                     -v /var/run/docker.sock:/var/run/docker.sock \
                     -v /data/jenkins/tools/sec_scan:/data/jenkins/tools/sec_scan \
                     --group-add ${gid}"
                ) {
                body()
            }
        }
    }
}

def golangBuildDocker(body) {
    node('local')  {
         docker.withRegistry('http://ccr.ccs.tencentyun.com/', 'ec5eecca-7aaf-4e7d-ae0f-8a43cb250cb1') {
            body()
        }

    }
}

def helmBuildDocker(body) {
    // 打印body里的${ENV}
    echo "helmBuildDocker: ${ENV}"
    if (env.ENV == 'EVOFLOW-DEV') { //dev环境仓库
        node('local')  {
            docker.withRegistry('http://registry.cn-qingdao.aliyuncs.com/', 'evoflow-dev') {
                body()
            }
        }
    } else {
        node('local')  { //pre | prod环境仓库
                body()
        }
    }
}

def nodejsBuildDocker(body) {
    node('local')  {
         docker.withRegistry('http://ccr.ccs.tencentyun.com/', 'ec5eecca-7aaf-4e7d-ae0f-8a43cb250cb1') {
            body()
        }

    }
}


def k8sDeployDocker(body) {
    node {
        gid = sh (
                script: "stat -c %g /var/run/docker.sock",
                returnStdout: true,
        ).trim()

        docker.withRegistry('https://im30cr.tencentcloudcr.com', 'im30cr') {
            docker.image("im30/k8s-deploy:v1.18.20").pull()
            docker.image("im30/k8s-deploy:v1.18.20").inside(
                    "-v /data/pkgs/.npm:/home/im30/.npm \
                     -v /home/im30/.ssh:/home/im30/.ssh \
                     -v /usr/bin/docker:/usr/bin/docker \
                     -v /var/run/docker.sock:/var/run/docker.sock \
                     --group-add ${gid}"
            ) {
                body()
            }
        }
    }
}